/**
 * 定义污水厂管理模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.ws.wsclcManager.wsclcInfo.PsWwtpAttrManager', ['water.entity.PsWwtpAttr']);
	
	module.controller('WsclcManagerPsWwtpAttrManagerController',function($wdp,$rootScope,$scope,$PsWwtpAttrService){
		
		/**
		 * 查询条件
		 */
		$scope.queryObject={};
		/**
		 * 污水厂数据
		 */
		$scope.wsclcData={};
		/**
		 * 编辑数据
		 */
		$scope.wsclcDataEdit={};
		/**
		 * 编辑页面折叠效果
		 */
		$scope.onEditSide = function(id){
			 var isedithidden = $("#"+id).next("div.editwsclccontent").is(":hidden");
			 $("div.editwsclccontent").slideUp();
			 if(isedithidden){
				 $("#"+id).next("div.editwsclccontent").slideDown();
			 }
			 else{
				 $("#"+id).next("div.editwsclccontent").slideUp();
			 }
		}
		/**
		 * 编辑按钮点击事件
		 */
		$scope.onEditClick = function(data){
			$scope.wsclcDataEdit = angular.copy(data);
			$scope.editDialog.open();
		}
		/**
		 * 取消按钮点击事件
		 */
		$scope.onCancelClick=function(){
			$scope.wsclcDataEdit={};
			$scope.editDialog.close();
		};
		/**
		 * 更新数据事件
		 */
		$scope.onUpdateClick=function(){
			$PsWwtpAttrService.updateModel($scope.wsclcDataEdit).then(function(d){
				$.messager.alert("保存成功","保存成功",'info');
				$scope._getWsclcList();
				$scope.editDialog.close();
			});
		};
		/**
		 * 打开关注度
		 */
		$scope.onOpenLevelData=function(){
			$waterDataCommon.getPageRows("WWTP_ATTENTION","ztxxList",{"WWTP_EXP_NO:like":$scope.queryObject.WWTP_ID},20,1);
			$itfreer.openWindow('GetStatusList');
		};
		/**
		 * 详情界面收合效果
		 */
		$("#baxx h5.wsclchead").bind("click",function(){
			var ishidden = $(this).next("div.wsclccontent").is(":hidden");
			 $("div.wsclccontent").slideUp();
			 if(ishidden){
				 $(this).next("div.wsclccontent").slideDown();
			 }
			 else{
				 $(this).next("div.wsclccontent").slideUp();
			 }
		 });
		/**
		 * 监控污水处理厂id变化
		 */
		if($wdp.viewValue.wwtpDetailParmWatch){
			$wdp.viewValue.wwtpDetailParmWatch();
		}
		$wdp.viewValue.wwtpDetailParmWatch = $rootScope.$watch(function(){return $wdp.viewValue.wwtpDetailParm;},function(){
			if(!$wdp.viewValue.wwtpDetailParm){
				return;
			}
			$scope.queryObject.WWTP_ID = $wdp.viewValue.wwtpDetailParm.WWTPID;
			$scope._getWsclcList();
        },true);
		/**
		 * 获取污水厂数据
		 */
		$scope._getWsclcList=function(){
			$PsWwtpAttrService.getList($scope.queryObject).then(function(d){
				if(d.data.length < 1){
					$scope.wsclcData = {};
					return;
				}
				var obj=d.data[0];
				 var url=obj.IMG;
				 var arr = new Array();
				 if(url!=""&&url!=null){
					 if(url.indexOf("|") > 0)
						{
							 arr = url.split("|");
							 obj.IMGURL=getHostBase()+String(arr[arr.length-1].toString().split(":")[0]);
					    }
						 else{
							 arr = url.split(":");
							 obj.IMGURL=getHostBase()+String(arr[0]);
						 }
				 }
				 else{
					 obj.IMGURL=getHostBase()+"wdp/images/noPic.png"; 
				 }
				 if(obj.EXP_NO==null)
				  {
					 obj.EXP_NO= obj.SDEEXP_NO;
				  }
				 if(obj.OBJECTID==null)
				  {
					 obj.OBJECTID=obj.SDEOBJECTID
				  }
				 $scope.wsclcData=obj;
			});
		};
		
	});
}(window, angular));
